using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

using MathSharp.Utils;

namespace MathSharp.Script
{
	public sealed class OperationPriorityTable
	{
		#region Singleton
		protected static OperationPriorityTable self = new OperationPriorityTable();
		
		public static OperationPriorityTable Instance {
			get {
				return self;
			}
		}
		#endregion		
		
		protected OperationPriorityTable() {
		}
		
		Dictionary<string, byte> operations = new Dictionary<string, byte>();
		
		public void Add(string operation, byte priority) {
			if (priority <= 0 || priority > 15)
				throw new ParseException(null, 0, 0, 0x0, "Значение приоритета должно быть в пределах от 1 до 15");
			operations.Add(operation, priority);
		}
		
		public OperationOrder TryGet(string operation) {
			byte res;
			if (operations.TryGetValue(operation, out res))
				return (OperationOrder)res;
			else
				return OperationOrder.None;
		}
	}
}